<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="楼盘名称" prop="name">
        <el-input
          v-model="queryParams.addressorname"
          placeholder="请输入楼盘名称/地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省" prop="province">
        <el-select v-model="queryParams.province" @change="getshiid()" clearable placeholder="请选择省">
          <el-option
            v-for="item in shengoptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="市" prop="city">
        <el-select v-model="queryParams.city" @change="getxianid()" clearable placeholder="请选择市">
          <el-option
            v-for="item in shioptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="区" prop="county">
        <el-select v-model="queryParams.county" clearable placeholder="请选择区">
          <el-option
            v-for="item in xianoptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="社区类型" prop="communityType">
        <el-select v-model="queryParams.communityType" clearable placeholder="请选择社区类型">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" border  style="width: 100%;margin-bottom: 20px;"  :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        type="index"
        width="50">
      </el-table-column>
      <el-table-column sortable label="楼盘ID" align="center" prop="id" />
      <el-table-column sortable label="楼盘名称" align="center" prop="name" />
      <el-table-column sortable label="地址" align="center" prop="address" />
      <el-table-column sortable label="物业类型" align="center" prop="communityType" >
        <template slot-scope="scope">
          <span v-if="scope.row.communityType==1">
            普通住宅
          </span>
          <span v-else-if="scope.row.communityType==2">
            公寓
          </span>
          <span v-else-if="scope.row.communityType==3">
            商住两用
          </span>
          <span v-else-if="scope.row.communityType==4">
            商业地产
          </span>
          <span v-else-if="scope.row.communityType==5">
            写字楼
          </span>
        </template>
      </el-table-column>
      <el-table-column sortable label="物业管理公司" align="center" prop="estate" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改楼盘信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>

    </el-dialog>
  </div>
</template>

<script>
  import {listInfo, getInfo, delInfo, addInfo, updateInfo, getsheng,getshi,getxian} from "@/api/system/info";

  export default {
    name: "Info",
    components: {
    },
    data() {
      return {
        //省
        shengoptions:[],
        shioptions:[],
        xianoptions:[],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 楼盘信息表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          addressorname: null,
          province: null,
          city: null,
          county: null,
          communityType: null,
        },
        options: [{
          value: '1',
          label: '普通住宅'
        }, {
          value: '2',
          label: '公寓'
        }, {
          value: '3',
          label: '商住两用'
        }, {
          value: '4',
          label: '商业地产'
        }, {
          value: '5',
          label: '写字楼'
        }],
        value: '',
      };
    },
    created() {
      this.getList();
      this.getsheng();
    },
    methods: {
      /** 查询楼盘信息列表 */
      getList() {
        this.loading = true;
        listInfo(this.queryParams).then(response => {
          this.infoList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          outsideId: null,
          name: null,
          province: null,
          city: null,
          county: null,
          commercialArea: null,
          subway: null,
          address: null,
          proportion: null,
          grossPlotRatio: null,
          greenCoverage: null,
          buildingCount: null,
          efficiency: null,
          developer: null,
          estate: null,
          introduce: null,
          communityType: null,
          buildingType: null,
          premisesType: null,
          updateTime: null,
          longItude: null,
          latItude: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$router.push({path:"addinfo"})
      },
      /** 提交按钮 */

      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除楼盘信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/info/export', {
          ...this.queryParams
        }, `premises_info.xlsx`)
      },
      getsheng(){
        getsheng().then(response => {
          this.shengoptions=response;
        });
      },
      getshiid(){
        console.log("getshi:",this.queryParams);
        getshi(this.queryParams).then(response=>{
          this.shioptions=response;
        })
      },
      getxianid(){
        console.log("getxian:",this.queryParams);
        getxian(this.queryParams).then(response=>{
          this.xianoptions=response;
        })
      }
    }
  };
</script>
